<template>
  <div id="index">
    <el-container>
      <el-header>
        <Headers />

      </el-header>
      <el-container>
        <el-aside width="250px">
          <Aside/>
        </el-aside>
        <el-main style="padding:0px;height:calc(90vh);overflow-y:auto">
          <div class="main"
            ref="main">
            <audio :src="music"
              ref="bgMusic">

            </audio>
            <router-view/>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// import { renderMessageList } from '@/public/js/util'
import Headers from "@/components/Headers";
import {
  receivesMessage,
  messageCount,
  getMessageUnread
} from "../public/js/message";
import "../public/scss/index.scss";
import { has } from "@/public/js/util";
import Aside from "./Aside.vue";
let music = require("@/public/audio/message_audio.mp3");

export default {
  name: "app",
  data() {
    return {
      orderClose: null,
      roomClose: null,
      count: null,
      music: music,
      checkinlist: "checkinlist",
      player: "",
      checkinList: [],
      miniList: [],
      orderList: [],
      total: 0
    };
  },
  created() {
    //this._getMessageUnread();
    this.music = music;
    this.messageCounts();
    if (!sessionStorage.token) {
      this.$router.push("/");
    }
  },
  mounted() {
    //this.player = this.$refs.bgMusic;
    if (has("messageunread", this)) {
      this._getMessageUnread();
      window.intervalClose = setInterval(() => {
        this._getMessageUnread();
      }, 30000);
    }
    sessionStorage.setItem("mainWidth", this.$refs.main.offsetWidth);
  },

  methods: {
    messageCounts() {
      messageCount().then(res => {
        if (res.data.errCode === 0)
          window.bus.$emit("messageCount", res.data.count);
      });
    },
    //消息弹框
    _getMessageUnread() {
      if (!sessionStorage.getItem("token")) {
        return false;
      }
      getMessageUnread().then(res => {
        if (res.data.errCode === 0) {
          this.$store.dispatch("setMessgeListAsyn", res.data);
          this.renderMessageList();
        }
      });
    },
    renderMessageList() {
      let messageData = this.$store.getters.getMessgeList;
      let { checkinCount, miniCount, orderCount } = messageData;
      window.bus.$emit("pageInformation", messageData);
      let messageCount =
        messageData.checkinCount +
        messageData.miniCount +
        messageData.orderCount;
      window.bus.$emit("messageCount", messageCount);
      this.count = messageData.orderCount;
      this.checkinList = messageData.checkinList;
      this.miniList = messageData.miniList;
      this.orderList = messageData.orderList;
      var checkItem = "";
      var miniItem = "";
      var orderItem = "";
      if (checkinCount || miniCount || orderCount) {
        this.$refs.bgMusic.play();
      }
      let offset = 0;
      // console.log(messageData);
      for (let k in messageData) {
        let cont = "";
        let name = "";
        let notify = "";
        let url = "";
        let icon = "";
        // console.log(messageData[k], k);
        if (k === "orderList") {
          cont = messageData.orderCount;
          name = "订单通知";
          offset = 0;
          notify = "notify_1";
          url = "#/index/order_detail";
          icon = '<i class="fa iconfont icon-dingdan"></i>';
        }
        if (k === "miniList") {
          cont = messageData.miniCount;
          name = "mini消费";
          offset = 120;
          notify = "notify_2";
          url = "#/index/list_goods_detail";
          icon = '<i class="fa iconfont icon-xiaofeizhe"></i>';
        }
        if (k === "checkinList") {
          cont = messageData.checkinCount;
          name = "退房通知";
          offset = 240;
          notify = "notify_3";
          url = "#/index/checkIn-detail";
          icon = '<i class="fa iconfont icon-37"></i>';
        }
        let list = "";
        if (messageData[k] instanceof Array && messageData[k].length > 0) {
          messageData[k].forEach(item => {
            list += `
                <a class="title" href="${url}?id=${item.omcId}&state=${
              item.id
            }">
                  <label style="margin-right:10px;">${
                    item.createTime
                  }</label><label>${item.title || null}</label>
                </a>
              `;
          });
          window[notify] = this.$notify({
            duration: 15000,
            position: "bottom-right",
            dangerouslyUseHTMLString: true,
            offset: offset,
            onClick: () => {},
            message: `
                    <div class="message-window">
                      <div class="window-left order-bg">
                        <div class="window-left-top">
                          ${icon}
                          <span>${cont}</span>
                          <p class="window-left-bt">${name}</p>
                        </div>                                               
                      </div>
                      <div class="window-right">
                        <div class="content">                         
                          ${list}
                          </div>
                        </div>
                      </div>
                    </div>`
          });
        }
      }
    }
  },
  components: {
    Headers,
    Aside
  }
};
</script>

<style lang="scss">
html * {
  margin: 0;
  padding: 0;
}
body {
  font-size: 12px;
  font-family: "微软雅黑";
  color: #415161;
  background-color: #e9ecf3;
}
a {
  text-decoration: none;
}

ul {
  list-style: none;
}

.el-notification {
  width: 550px;
  padding: 0;
  border-radius: initial;
  .el-notification__group {
    margin: 0;
    .el-notification__content {
      margin: 0;
    }
  }
}
.message-window {
  width: 550px;
  overflow: hidden;
  .window-left,
  .window-right {
    float: left;
  }
  .window-left {
    .window-left-top {
      position: relative;
      height: 80px;
    }
    .window-left-bt {
      width: 100%;
      height: 40px;
      position: absolute;
      top: 37px;
      color: #fff;
    }
    span {
      position: absolute;
      top: 10px;
      right: 10px;
      background-color: red;
      color: #fff;
      width: 18px;
      height: 18px;
      line-height: 18px;
      border-radius: 50%;
      font-size: 12px;
      text-align: center;
    }
  }
  .window-right {
    width: 450px;
    padding-left: 20px;
    box-sizing: border-box;
    padding-top: 20px;
    .content {
      h1 {
        font-size: 14px;
      }
      .title {
        width: 390px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        display: inline-block;
        margin-bottom: 3px;
        label {
          width: 100%;
          font-size: 14px;
          color: #415161;
        }
      }
    }
  }
  .room-bg {
    background-color: #ff9913;
  }
  .order-bg {
    background-color: #6d2377;
  }
  .window-left {
    width: 100px;
    height: 120px;
    line-height: 7.5;
    text-align: center;
    i {
      position: absolute;
      font-size: 40px;
      top: 27px;
      color: #fff;
      left: 30px;
    }
  }
}

.el-header {
  background-color: #6d2377;
  color: white;
  text-align: center;
  width: 100%;
  height: 64px !important;
  padding-right: 0;
  // position: fixed;
  // top:0;
  // left:0;
}

.aside-wrapper {
  .el-menu-item:focus,
  .el-menu-item:hover {
    background-color: #6d2377;
    i,
    span {
      color: white;
    }
    .el-menu-item {
      height: 50px;
      line-height: 50px;
    }
  }
  /*侧边栏*/
  .will-aside-list {
    position: relative;
    height: 56px;
    line-height: 56px;
    cursor: pointer;
    font-size: 16px;
    color: #415161;
    .will-aside-list-url {
      position: absolute;
      top: 0;
      left: 160px;
      z-index: 99999;
      padding: 20px;
      background-color: #fff;
      width: 200px;
      display: none;
      color: #415161;
      box-shadow: 3px 3px 3px #e1e1e1;
    }
  }
  .will-aside-list:hover,
  .will-aside-list:focus {
    background-color: #6d2377;
    color: #fff;
    font-size: 16px;
    .will-aside-list-url {
      display: block;
    }
  }
}
.router-link-active {
  li {
    background: #6d2377;
    i,
    span {
      color: #fff !important;
    }
  }
}
.aside-wrapper .el-menu {
  border-right: none;
  padding-top: 10px;
}

.el-main {
  background-color: #fff;
  text-align: center;
  padding-left: 0 !important;
  padding-bottom: 0;
  margin-top: 20px;
  margin-right: 20px;
  padding: 0px;
}

.el-submenu .el-menu-item {
  min-width: auto;
}

.el-submenu__title,
.el-menu-item {
  text-align: left;
  padding-left: 40px;
}

.el-menu-item:first-child {
  padding-left: 40px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-popover {
  min-width: 50px;
  :first-child {
    border-left: none;
  }
}
.el-breadcrumb {
  background-color: #e9ecf3;
  padding-bottom: 20px;
}
.easytrip-icon-account,
.easytrip-icon-out {
  background-size: cover;
  background-repeat: no-repeat;
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: sub;
  margin-left: 5px;
}

.easytrip-icon-account {
  background-image: url(../public/image/account.png);
}

.easytrip-icon-out {
  background-image: url(../public/image/out.png);
}
/*下拉小三角*/
// .el-popper .popper__arrow,
// .el-popper .popper__arrow:after {
//   display: none !important;
//   position: absolute;
//   width: 0;
//   height: 0;
//   border-color: transparent;
//   border-style: none;
//   border-width: 0 !important;
// }
/*下拉样式*/

.header-popover.el-popover {
  /*width: 140px!important;*/
  padding: 10px 0;
  color: #415161;
  border-radius: 0;
  border: none;
  div:hover {
    background-color: #eff1f8;
    color: #6d2377;
  }
  .account,
  .out {
    padding: 0 30px 0 20px;
    margin-bottom: 0px;
    height: 50px;
    line-height: 50px;
    box-sizing: border-box;
    a {
      color: #415161 !important;
    }
  }
  // .account[data-v-426f70a6], .out[data-v-426f70a6]{
  //   padding: 0 30px 0 20px;
  //   margin-bottom: 0px;
  //   height: 50px;
  //   line-height: 50px;
  //   box-sizing: border-box;
  //   a{
  //     color: #415161!important;
  //   }

  // }
  .account[data-v-426f70a6]:hover,
  .out[data-v-426f70a6]:hover {
    a {
      color: #6d2377 !important;
    }
  }
}
/*表格高度*/
el-table__empty-block {
  width: 100% !important;
}
.el-table {
  font-size: 12px;
}
.el-table td {
  padding: 10px 0;
  color: #415161;
}
.el-table th {
  padding: 13px 0;
  background-color: #eef1f9 !important;
  color: #415161;
  font-weight: normal;
  font-size: 12px;
}
</style>


